﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;
using Hkwl.WorldExpo.Merchant.Logs;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class Operate : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string opType = Request.QueryString["OpType"];
            if (opType == "GroupDel")
            {
                int groupId = int.Parse(Request.QueryString["GroupId"]);

                if (ServiceLocator.IClientService.DeleteNxGroup(groupId))
                {
                    if (ServiceLocator.IClientService.DeleteNxGroupClientByGroup(groupId)) ;
                    {
                        JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "REMOVAL_SUCCESS") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','GroupList.aspx?GroupId=" + groupId + "')", this.Page);
                    }
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "REMOVE_FAILED") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','GroupList.aspx?GroupId=" + groupId + "')", this.Page);
                }
            }
            if (opType == "GroupClientDel")
            {
                int groupId = int.Parse(Request.QueryString["GroupId"]);
                int clientId = int.Parse(Request.QueryString["ClientId"]);
                if (ServiceLocator.IClientService.DeleteNxGroupClient(groupId, clientId))
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "REMOVAL_SUCCESS") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','GroupClientList.aspx?GroupId=" + groupId + "')", this.Page);
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "REMOVE_FAILED") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','GroupClientList.aspx?GroupId=" + groupId + "')", this.Page);
                }
            }
            if (opType == "ClientDel")
            {
                int clientId = int.Parse(Request.QueryString["ClientId"]);
                NxClient client = ServiceLocator.IClientService.GetNxClientById(clientId);
                client.Status = (int)EnumStatus.ClientStatus.删除;

                if (ServiceLocator.IClientService.UpdateNxClient(client))
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "DELETE_SUCCESS") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ClientList.aspx')", this.Page);
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "DELETE_FAILED") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ClientList.aspx')", this.Page);
                }
            }
            if (opType == "ProjectPublish")
            {
                int projectId = int.Parse(Request.QueryString["ProjectId"]);
                NxProject project = ServiceLocator.IProjectService.GetNxProjectById(projectId);
                project.Status = 2;
                if (ServiceLocator.IProjectService.UpdateNxProject(project))
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "PUBLISHED_SUCCESSFUL") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ProjectList.aspx')", this.Page);
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "PUBLISHED_FAILED") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ProjectList.aspx')", this.Page);
                }
            }
            if (opType == "ProjectDel")
            {
                int projectId = int.Parse(Request.QueryString["ProjectId"]);
                NxProject project = ServiceLocator.IProjectService.GetNxProjectById(projectId);
                project.Status = (int)EnumStatus.ProjectStatus.删除;

                if (ServiceLocator.IProjectService.UpdateNxProject(project))
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "DELETE_SUCCESS") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ProjectList.aspx')", this.Page);
                }
                else
                {
                    JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "DELETE_FAILED") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','ProjectList.aspx')", this.Page);
                }
            }
        }
    }
}
